﻿#include "Damage.h"
#include "../Forms/Client.CMain.h"
#include "../Settings.h"

using namespace Client::MirControls;

namespace Client::MirObjects
{

    Damage::Damage(const std::string &text, int duration, Color *colour, int distance)
    {
        ExpireTime = static_cast<long long>(CMain::Time + duration);
        Text = text;
        Distance = distance;
        Factor = duration / this->Distance;
        Colour = colour;
    }

    void Damage::Draw(Point *displayLocation)
    {
        long long timeRemaining = ExpireTime - CMain::Time;

        if (DamageLabel == nullptr)
        {
            DamageLabel = new MirLabel();
            DamageLabel->setAutoSize(true);
            DamageLabel->setBackColour(Color::Transparent);
            DamageLabel->setForeColour(Colour);
            DamageLabel->setOutLine(true);
            DamageLabel->setOutLineColour(Color::Black);
            DamageLabel->setText(Text);
            Font tempVar(Settings::FontName, 8.0F, FontStyle::Bold);
            DamageLabel->setFont(&tempVar);
        }

        displayLocation->Offset(static_cast<int>(15 - (Text->length() * 3)), static_cast<int>((static_cast<int>(static_cast<double>(timeRemaining) / Factor)) - Distance) - 75 - Offset);

        DamageLabel->setLocation(displayLocation);
        DamageLabel->Draw();
    }
}
